/*
 * Copyright (c) 2017 22420103@QQ.COM 版权所有
 */
package com.lehe.entry.page;

import java.util.ArrayList;
import java.util.List;

/**
 * 分页实体类<br>
 *
 * @author 王丹
 * @date 2017-02-28
 */
public class PageDto {

    /** 每页数据量默认值*/
    private static final int PAGE_RECORD = 20;
    /** 总记录数 */
    private int recordCount = 0;
    /** 每页的数量 */
    private int pageSize = PAGE_RECORD;
    /** 当前页 默认值1*/
    private int pageIndex = 1;
    
    //以下属性均有计算得出，只提供get方法不提供set方法
    private boolean showFirst;//是否显示首页
    private boolean showLast;//是否显示最后一夜
    private Integer totalPageCount;//总页数
    private List<Integer> showPageIndexs;//显示那几页的按钮
    private int btnCount = 5;//要显示的按钮个数，一般为奇数个
    
	public boolean isShowFirst() {
		showFirst = pageIndex != 1;
		return showFirst;
	}

	public boolean isShowLast() {
		showLast = pageIndex != getTotalPageCount();
		return showLast;
	}

	public Integer getTotalPageCount() {
		totalPageCount = recordCount % pageSize == 0?recordCount / pageSize:recordCount / pageSize + 1;
		return totalPageCount;
	}

	public List<Integer> getShowPageIndexs() {
		
		
		List<Integer> result = new ArrayList<Integer>(btnCount);
		if(pageIndex <= btnCount/2 + 1){
			for(int i = 0 ; i < btnCount ; i ++){
				if(i + 1 > this.getTotalPageCount()){
					break;
				}
				result.add(i + 1);
			}
			showPageIndexs = result;
		}else{
			for(int i = pageIndex - btnCount/2; i < btnCount + pageIndex - btnCount/2 ; i ++){
				if(i > this.getTotalPageCount()){
					break;
				}
				result.add(i);
			}
			showPageIndexs = result;
		}
		
		return showPageIndexs;
	}

	public PageDto(Integer pageIndex,Integer pageSize) {
		super();
		if(pageSize == null || pageIndex == null){
			return;
		}
		
		this.pageSize = pageSize;
		this.pageIndex = pageIndex;
	}
	
	public int getRecordCount() {
		return recordCount;
	}
	public void setRecordCount(int recordCount) {
		this.recordCount = recordCount;
	}
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	public int getPageIndex() {
		return pageIndex;
	}
	public void setPageIndex(int pageIndex) {
		this.pageIndex = pageIndex;
	}
   
}
